import React from "react";
import { useSearchParams, useNavigate } from "react-router-dom";
import { NavBar, Toast } from "antd-mobile";
import { Cell } from "react-vant";
import { Alipay, WechatPay, Checked } from "@react-vant/icons";
import http from "../../api/htpp";

function Index() {
  const navigate = useNavigate();
  const [sq] = useSearchParams();
  const id = sq.get("id");
  const title = sq.get("title");
  const price = sq.get("price");

  const handelPay = async () => {
    const res = await http.get("/api/pay", { params: { id, title, price } });
    const { code, data, message } = res.data;
    if (code === 200) {
      window.location.href = data;
    } else {
      Toast.show({
        content: message,
        icon: "fail",
        duration: 1000,
      });
    }
  };

  return (
    <div>
      <NavBar onBack={() => navigate(-1)}>订单</NavBar>
      <div>
        <Cell
          title="支付宝"
          icon={<Alipay color="blue" />}
          onClick={() => handelPay()}
        />
      </div>
    </div>
  );
}

export default Index;
